DSA Homework 2

Roger Jang


Due date: 20190408 23:59:59

Longest Common Prefix (LCP)

Problem definition

The length of the longest common prefix of two strings A[0..m) and B[0..n), denoted by lcp(A,B), is the largest integer $k \leq min\{m,n\}$ such that A[0..k)=B[0..k). In this homework, we need to build a data structure that can compute LCP efficiently.

First of all, we need to construct a large set of strings, as follows.

For example: Then you have to answer q questions. For every question, you are given two positive integers i, j , please output the lcp( i'th string, j'th string ) in a line.

I/O formats

I/O Examples

Open Test Sets

Hints and Suggestions